package me.sdevil507.services.controller;

import lombok.extern.slf4j.Slf4j;
import me.sdevil507.org.dto.OrgResultDto;
import me.sdevil507.org.mapper.OrgMapper;
import me.sdevil507.org.po.OrgPo;
import me.sdevil507.org.service.OrgService;
import me.sdevil507.services.dto.ServicesSearchOrgInfoDTO;
import me.sdevil507.supports.result.ApiResultDTO;
import me.sdevil507.supports.result.ApiResultGenerator;
import me.sdevil507.supports.status.ApiStatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author hp
 * @Date 2021/2/24 10:37
 * @Description 服务端查询智库信息
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/services/getOrgInfo")
@Slf4j
public class ServicesOrgController {

    @Autowired
    private OrgService orgService;

    @Autowired
    private OrgMapper orgMapper;

    /**
     * 获取某一个智库的详细信息
     *
     * @return
     */
    @PostMapping("/getOrgInfoByOrgId")
    public ApiResultDTO getOrgInfoByOrgId(@RequestBody ServicesSearchOrgInfoDTO searchOrgInfoDTO) {
        OrgPo orgPo = orgService.getOrgInfoByOrgId(searchOrgInfoDTO.getOrgId());

        OrgResultDto orgResultDto = orgMapper.po2dto(orgPo);
        if(!StringUtils.isEmpty(orgResultDto.getClassify())){
            String result = orgService.getClassifyName(orgResultDto.getClassify().split(","));
            orgResultDto.setClassifyName(result);
        }


        return ApiResultGenerator.create(ApiStatusCode.SUCCESS.getCode(), ApiStatusCode.SUCCESS.getDescription(), orgResultDto);
    }

}
